<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id ="t1">
<input type="text" id ="t2">
<input type="button" value="加" onclick="f('+')">
<input type="button" value="减" onclick="f('-')">
<input type="button" value="乘" onclick="f('*')">
<input type="button" value="除" onclick="f('/')">
<div>结果</div>
<script>
    let t1 = document.querySelector("#t1")
    let t2 = document.querySelector("#t2")
    let d = document.querySelector("div");
    // t1 = parseFloat(t1.value);
    // t2 = parseFloat(t2.value)
    let i = document.querySelector("input")
    console.log(typeof i)
    if(isNaN(t1.value)||isNaN(t2.value)){
        d.innerText="输入有误"
    }
    function f(s){
        switch (s){
            case"+":
                d.innerText = "结果:" + (t1.value * 1 + t2.value * 1);
                break;
            case"-":
                d.innerText = "结果:"+(t1.value - t2.value)
                break;
            case"*":
                d.innerText = "结果:"+(t1.value * t2.value)
                break
            case"/":
                if(t2.value*1==0){
                    d.innerText="错误，除数不能为0";
                }else {
                    d.innerText = "结果:"+(t1.value /t2.value)
                }
        }


    }
    function add() {
        d.innerText = "结果:" + (t1.value * 1 + t2.value * 1)
        console.log(typeof i)
    }
    function sub() {
        d.innerText = "结果:"+(t1.value - t2.value)
    }
    function mul() {
        d.innerText = "结果:"+(t1.value * t2.value)
    }
    function divide() {
        if(t1.value*1==0){
            d.innerText="数据不合法";
        }else {
            d.innerText = "结果:"+(t1.value /t2.value)
        }

    }

</script>
</body>
</html>